package com.xx566.socket.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketServer {

	private static ServerSocket serverSocket;

    public static void main(String[] args) throws IOException {
        serverSocket = new ServerSocket(8888);
        while (true) {
            final Socket socket = serverSocket.accept();
            try {
                // 获取输入流
                BufferedReader inputStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                // 获取输出流
                PrintWriter outputStream = new PrintWriter(socket.getOutputStream());
                // 读取输入
                String readString = inputStream.readLine();
                if ("admin".equals(readString)) {
                    outputStream.println("登录成功!");
                } else {
                    outputStream.println("登录失败!");
                }
                outputStream.flush();
                // 关闭
                outputStream.close();
                inputStream.close();
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
